package com.test.executorPool;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 *
 * 如果 maxSise > 运行的线程 > corePoolSize  情况下。 进入等待队列
 *
 *
 * @author:wesley
 */
public class ThreadPoolExecutorTest2 {


    public static void main(String[] args) throws InterruptedException {

        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                try {
                    System.out.println(Thread.currentThread().getName()+"--"+System.currentTimeMillis());
                    Thread.sleep(300);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };


        ThreadPoolExecutor executor = new ThreadPoolExecutor(7, 10 ,
                5, TimeUnit.SECONDS, new LinkedBlockingDeque<Runnable>());

        executor.execute(runnable);
        executor.execute(runnable);
        executor.execute(runnable);
        executor.execute(runnable);
        executor.execute(runnable);
        executor.execute(runnable);
        executor.execute(runnable);

        executor.execute(runnable);
        executor.execute(runnable);
        executor.execute(runnable);
        executor.execute(runnable);


        // 此时打印获取队列中的个数
        Thread.sleep(100);
        System.out.println("A==="+executor.getCorePoolSize());
        System.out.println("A==="+executor.getMaximumPoolSize());
        System.out.println("A==="+executor.getQueue().size());


        // 睡眠1秒 ，等待队列中的线程完成之后， 等待队列大小是0
        Thread.sleep(1000);
        System.out.println("b==="+executor.getCorePoolSize());
        System.out.println("b==="+executor.getMaximumPoolSize());
        System.out.println("b==="+executor.getQueue().size());

    }



}
